<template>
  <el-card shadow="never" style="margin-bottom: 0">
    <template #header> 销售统计 </template>
    <div ref="divRef" style="width: 100%; height: 300px"></div>
  </el-card>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted, watchEffect } from 'vue'
import useEcharts from '@/hooks/web/useEcharts'
import { EChartsOption } from 'echarts'

export default defineComponent({
  setup() {
    const divRef = ref<HTMLElement>()

    const options: EChartsOption = {
      legend: {
        bottom: 0,
        data: ['Visits', 'Sales']
      },
      tooltip: {},
      radar: {
        radius: '60%',
        splitNumber: 8,
        indicator: [
          {
            text: '2017',
            max: 100
          },
          {
            text: '2017',
            max: 100
          },
          {
            text: '2018',
            max: 100
          },
          {
            text: '2019',
            max: 100
          },
          {
            text: '2020',
            max: 100
          },
          {
            text: '2021',
            max: 100
          }
        ]
      },
      series: [
        {
          type: 'radar',
          symbolSize: 0,
          areaStyle: {
            shadowBlur: 0,
            shadowColor: 'rgba(0,0,0,.2)',
            shadowOffsetX: 0,
            shadowOffsetY: 10,
            opacity: 1
          },
          data: [
            {
              value: [90, 50, 86, 40, 50, 20],
              name: 'Visits',
              itemStyle: {
                color: '#b6a2de'
              }
            },
            {
              value: [70, 75, 70, 76, 20, 85],
              name: 'Sales',
              itemStyle: {
                color: '#67e0e3'
              }
            }
          ]
        }
      ]
    }

    onMounted(() => {
      const { setOptions } = useEcharts(divRef.value!)

      watchEffect(() => {
        setOptions(options)
      })
    })

    return {
      divRef
    }
  }
})
</script>

<style scoped></style>
